<%@ page import="java.util.Calendar"%>
<%@ page import="java.util.GregorianCalendar"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="javax.xml.soap.Detail"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%
         request.setCharacterEncoding("UTF-8");
%>

<html><body>
<%
Statement sql;
Connection con;
ResultSet rs;
   try{
       Class.forName("com.mysql.jdbc.Driver");
       }
       catch(Exception e){
    	   out.print("加载驱动失败");
       };
       
    	try{ 
    		
      String uri="jdbc:mysql://localhost:3306/sharing"; 
    	  con = DriverManager.getConnection(uri,"root","ZHUBI123.");
    	  
   String name=request.getParameter("name");
   String email=request.getParameter("email");
   String subject = request.getParameter("subject");
   String content = request.getParameter("content");

   int year,month,day,hour,minute,second;
   String time;
   GregorianCalendar calendar;
   calendar=new GregorianCalendar();
   year=calendar.get(Calendar.YEAR);
   month=calendar.get(Calendar.MONTH)+1;
   day=calendar.get(Calendar.DAY_OF_MONTH);
   hour=calendar.get(Calendar.HOUR_OF_DAY);
   minute=calendar.get(Calendar.MINUTE);
   second=calendar.get(Calendar.SECOND);
   time = year + "年" + month + "月" + day + "日" + hour + "：" + minute
			+ "：" + second;
   byte[] bb=content.getBytes("UTF-8");
   content=new String(bb,"UTF-8");
   byte[] cc=subject.getBytes("UTF-8");
   subject=new String(cc,"UTF-8");
   String username = session.getAttribute("username").toString();
   String updateCondition1="insert into discuss ( name, email, subject, content, time, username) values( '"+ name+  
		   "','"+ email	+ "','"	+ subject+ "','"+ content+ "','"+ time + "','" + username + "')";
   sql=con.createStatement();

   sql.executeUpdate(updateCondition1);
   
   out.print("发表成功");

        response.sendRedirect("discuss.jsp");}
        catch(SQLException e){out.print("更新失败");}
        %>
   </body></html>
